/*
 *  Copyright (C) 2013 KangHua <kanghua151@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License version 2 as published by
 *  the Free Software Foundation.
 */

#ifndef _FFSSIM_H_
#define _FFSSIM_H_

#include <time.h>
#include <stdint.h>
#include "storage.h"

#define MAX_FILE_NAME_LEN 128U
struct inode {
	uint64_t length;
	uint64_t mtime;             /* time of last modification */
	int64_t blocks[12];         /* the first 8KB*12=96KB */
	int64_t iblock;             /* the next 8KB/8*8KB=8MB */
	int64_t doubly_iblock;      /* the next 8K/8*8K/8*8K=8GB */
	int64_t triply_iblock;      /* the next 8K/8*8K/8*8K/8*8K=8TB */
} __attribute__((packed));  

struct inode_map_entry {
	uint64_t inode_no;	              /* inode number */
	uint64_t inode_addr;		/* inode's DISK address */ 
} __attribute__((packed)); 

struct super_block {
	uint32_t block_size;		        /* max data block size */
	uint64_t max_fs_size;               /* max filesystem size */
	uint32_t chunk_size;                /*data chunk size */
	char fsname[MAX_FILE_NAME_LEN];		/* record the file's name */
};

struct log_header {
	uint8_t  cflag;            /*for compress?*/
	uint32_t log_size;
	uint64_t ctime;           /* create time */
	uint32_t start_db_no;     /* log first db no*/
	uint32_t db_num;	      /* db amounts */
	uint32_t ib_num;	      /* ib amount */
	char data[0];
} __attribute__((packed)); 

#define LOG_HEADER_LENGTH sizeof(struct log_header)
/* The control structure in RAM */
struct ffssim_ctrl {
	struct   super_block sb;	        	/* the sb in RAM */
	struct   inode_map_entry imap_entry;	/* the inode map in RAM */
	struct   inode inode;		
	uint32_t last_segno;	/* the current segment */
	uint32_t last_offset;	/* the current offset in current segment */
	struct   back_storage *storage;
	uint32_t last_read_segno;
	uint32_t last_rsegfile_offset;/* last segfile end offset when last open */
	uint64_t last_write_timestamp;
	uint64_t last_read_timestamp;
	int rw_inode_flag;
	uint32_t start_segno;
};
#endif
